/**
 * 
 */
package com.effectivsocial.controller;

import java.util.Locale;

import javax.inject.Inject;
import javax.validation.Valid;

import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;

import com.effectivsocial.domain.NetworkType;
import com.effectivsocial.domain.SocialNetwork;
import com.effectivsocial.service.api.SocialNetworkService;


/**
 * @author Dhrubo
 *
 */
@Controller
@Slf4j
@RequestMapping("/network")
public class CreateFacebookController {
	
	@Inject
	private SocialNetworkService socialNetworkService;

	@RequestMapping(value="/newfacebook") 
	public String showForm(Model model){
				
		log.info("----------------------New Facebook ---------------------------");
	
		
		model.addAttribute(new SocialNetwork());
		
		return "createfacebook";
	}
	
		
	@RequestMapping(value="/savefacebook")
	public String submitForm(@Valid SocialNetwork network, BindingResult result, Locale locale){
		
		NetworkType networkType = new NetworkType();
		networkType.setType("NetworkType");
		networkType.setName("Facebook");
		
		
		network.setNetworkType(networkType);
		
		log.info("Error = {}", result);
		
		if(!result.hasErrors()){
			socialNetworkService.save(network);
		}
		
		return "createfacebook";
	}
	
	
}
